<!DOCTYPE html>
<html>
<head>
    <title>Geometry Interfaces: DOMMatrix and DOMMatrixReadOnly constructors</title>
    <link rel="author" title="Dirk Schulze" href="mailto:dschulze@adobe.com" />
    <link rel="help" href="http://www.w3.org/TR/geometry-1/#DOMMatrix">
    <link rel="help" href="http://www.w3.org/TR/geometry-1/#dommatrix-constructors">
    <link rel="help" href="http://www.w3.org/TR/geometry-1/#dom-dommatrix-dommatrix">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
</head>
<body>
    <p>Test DOMMatrix and DOMMatrixReadOnly contructors</p>
    <div id="log"></div>
    <script>
        initial = {
            m11: 1, m21: 0, m31: 0, m41: 0, 
            m12: 0, m22: 1, m32: 0, m42: 0, 
            m13: 0, m23: 0, m33: 1, m43: 0, 
            m14: 0, m24: 0, m34: 0, m44: 1,
            is2D: true,
            isIdentity: true 
        };
        scaleTranslate2D = {
            m11: 2, m21: 0, m31: 0, m41: 10, 
            m12: 0, m22: 2, m32: 0, m42: 10, 
            m13: 0, m23: 0, m33: 1, m43: 0, 
            m14: 0, m24: 0, m34: 0, m44: 1,
            is2D: true,
            isIdentity: true 
        };

        test(function() {
            checkDOMMatrix(new DOMMatrix(), initial);
        },'testConstructor0');
        test(function() {
            checkDOMMatrix(new DOMMatrix(new DOMMatrix()), initial);
        },'testConstructor1');
        test(function() {
            var float32Array = new Float32Array(
                2.0, 0.0, 0.0, 0.0,
                0.0, 2.0, 0.0, 0.0,
                0.0, 0.0, 1.0, 0.0,
                10.0, 10.0, 0.0, 1.0);
            checkDOMMatrix(new DOMMatrix(float32Array), scaleTranslate2D);
        },'testConstructor2');
        test(function() {
            var float32Array = new Float32Array(2.0, 0.0, 0.0, 2.0, 10.0, 10.0);
            checkDOMMatrix(new DOMMatrix(float32Array), scaleTranslate2D);
        },'testConstructor3');
        test(function() {
            var float64Array = new Float64Array([
                2.0, 0.0, 0.0, 0.0,
                0.0, 2.0, 0.0, 0.0,
                0.0, 0.0, 1.0, 0.0,
                10.0, 10.0, 0.0, 1.0]);
            checkDOMMatrix(new DOMMatrix(float64Array), scaleTranslate2D);
        },'testConstructor4');
        test(function() {
            var float64Array = new Float64Array(2.0, 0.0, 0.0, 2.0, 10.0, 10.0);
            checkDOMMatrix(new DOMMatrix(float64Array), scaleTranslate2D);
        },'testConstructor5');
        test(function() {
            var sequence = [
                2.0, 0.0, 0.0, 0.0,
                0.0, 2.0, 0.0, 0.0,
                0.0, 0.0, 1.0, 0.0,
                10.0, 10.0, 0.0, 1.0];
            checkDOMMatrix(new DOMMatrix(sequence), scaleTranslate2D);
        },'testConstructor6');
        test(function() {
            var sequence = [ 2.0, 0.0, 0.0, 2.0, 10.0, 10.0];
            checkDOMMatrix(new DOMMatrix(float64Array), scaleTranslate2D);
        },'testConstructor7');
        test(function() {
            var string = 'scale(2) translateX(5px) translateY(5px)';
            checkDOMMatrix(new DOMMatrix(string), scaleTranslate2D);
        },'testConstructor8');
        test(function() {
            var string = 'scale(2 2) translateX(5) translateY(5)';
            checkDOMMatrix(new DOMMatrix(string), scaleTranslate2D);
        },'testConstructor9');
        test(function() {
            var string = 'scale(2, 2), translateX(5)  ,translateY(5)';
            checkDOMMatrix(new DOMMatrix(string), scaleTranslate2D);
        },'testConstructor10');
        test(function() {
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX    (5px)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('scale(2)translateX(5px)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5em)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5ex)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5ch)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5rem)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5vw)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5vh)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5vmin)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5vmax)'); });
            assert_throws('SyntaxError', function() { new DOMMatrix('translateX(5%)'); });
        },'testConstructor11');
        test(function() {
            var sequence = [
                2.0, 1.0, 0.0, 0.0,
                1.0, 2.0, 0.0, 0.0,
                0.0, 0.0, 1.0, 0.0,
                10.0, 10.0, 0.0, 1.0];
            checkDOMMatrix(new DOMMatrix(sequence), {
                m11: 2, m21: 1, m31: 0, m41: 10, 
                m12: 1, m22: 2, m32: 0, m42: 10, 
                m13: 0, m23: 0, m33: 1, m43: 0, 
                m14: 0, m24: 0, m34: 0, m44: 1,
                is2D: false,
                isIdentity: false 
            });
        },'testConstructor12');
        test(function() {
            var matrix = new DOMMatrix([
                2.0, 1.0, 0.0, 0.0,
                1.0, 2.0, 0.0, 0.0,
                0.0, 0.0, 1.0, 0.0,
                10.0, 10.0, 0.0, 1.0]);
            checkDOMMatrix(new DOMMatrix(matrix), {
                m11: 2, m21: 1, m31: 0, m41: 10, 
                m12: 1, m22: 2, m32: 0, m42: 10, 
                m13: 0, m23: 0, m33: 1, m43: 0, 
                m14: 0, m24: 0, m34: 0, m44: 1,
                is2D: false,
                isIdentity: false 
            });
        },'testConstructor13');
        test(function() {
            assert_throws(new TypeError(), function() { new DOMMatrixReadOnly(); });
        },'testConstructorIllegal0');
        test(function() {
            var string = 'scale(2, 2), translateX(5px) translateY(5px)';
            assert_throws(new TypeError(), function() { new DOMMatrixReadOnly(string); });
        },'testConstructorIllegal1');
        test(function() {
            var sequence = [ 2.0, 0.0, 0.0, 2.0, 10.0, 10.0];
            assert_throws(new TypeError(), function() { new DOMMatrixReadOnly(sequence); });
        },'testConstructorIllegal2');

        function checkDOMMatrix(m, exp) {
            assert_equals(m.m11, exp.m11, "Expected value for m11 is " + exp.m11);
            assert_equals(m.m12, exp.m12, "Expected value for m12 is " + exp.m12);
            assert_equals(m.m13, exp.m13, "Expected value for m13 is " + exp.m13);
            assert_equals(m.m14, exp.m14, "Expected value for m14 is " + exp.m14);
            assert_equals(m.m21, exp.m21, "Expected value for m21 is " + exp.m21);
            assert_equals(m.m22, exp.m22, "Expected value for m22 is " + exp.m22);
            assert_equals(m.m23, exp.m23, "Expected value for m23 is " + exp.m23);
            assert_equals(m.m24, exp.m24, "Expected value for m24 is " + exp.m24);
            assert_equals(m.m31, exp.m31, "Expected value for m31 is " + exp.m31);
            assert_equals(m.m32, exp.m32, "Expected value for m32 is " + exp.m32);
            assert_equals(m.m33, exp.m33, "Expected value for m33 is " + exp.m33);
            assert_equals(m.m34, exp.m34, "Expected value for m34 is " + exp.m34);
            assert_equals(m.m41, exp.m41, "Expected value for m41 is " + exp.m41);
            assert_equals(m.m42, exp.m42, "Expected value for m42 is " + exp.m42);
            assert_equals(m.m43, exp.m43, "Expected value for m43 is " + exp.m43);
            assert_equals(m.m44, exp.m44, "Expected value for m44 is " + exp.m44);
            assert_equals(m.is2D, exp.is2D, "Expected value for is2D is " + exp.is2D);
            assert_equals(m.isIdentity, exp.isIdentity, "Expected value for isIdentity is " + exp.isIdentity);
        }

    </script>
</body>
</html>
